<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of FileService
 *
 * @author Administrator
 */
class FileService {

    function listFileByAppId($id) {
        $fileTable = D('file');
        $files = $fileTable->join('app_file af on file.id = af.file_id')
                        ->join('app a on af.app_id = a.id')
                        ->where(array('a.id' => $id))->field('file.*')->select();
        return $files;
    }

    function insert($file) {
        return D('file')->add($file);
    }

    function deleteUploadFile($filename) {
        $filename = str_replace('..', './App/Tpl/default', $filename);
        if (file_exists($filename)) {
            unlink($filename);
        }
        //删除缩略图
        if (file_exists('thumb_' . $filename)) {
            unlink('thumb_' . $filename);
        }
    }

}

?>
